package test;
import java.util.HashMap;
import java.util.Set;
public class ShoppingCart {
	private HashMap<Goods,Integer> map=new HashMap<Goods,Integer>();
	public void add(Goods goods,int count) {
		Integer cnt=map.get(goods);
		if(cnt!=null) {
			cnt+=count;
			map.remove(goods);
		}else {
			cnt=count;
		}
		map.put(goods, cnt);
	}
	public int get(Goods goods) {
		Integer cnt=map.get(goods);
		int count=0;
		if(cnt!=null) {
			count=cnt;
		}
		return count;
	}
	public Set<Goods>keySet(){
		return map.keySet();
	}
	public int check() {
		int total=0;
		for(Goods goods:map.keySet()) {
			Integer cnt=map.get(goods);
			total +=cnt*goods.getPrice();
		}
		return total;
	}
	
}
